<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title th:if="${product.id} == null">添加产品</title>
    <title th:if="${product.id} != null">编辑产品</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <div class="container-fluid">
            <a class="navbar-brand" href="/products">林荣辉的产品管理系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="/products">产品列表</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="#" th:if="${product.id} == null">添加产品</a>
                        <a class="nav-link active" href="#" th:if="${product.id} != null">编辑产品</a>
                    </li>
                </ul>
            </div>
            <div class="d-flex">
                <span class="navbar-text me-3" th:text="${session.username}"></span>
                <a href="/logout" class="btn btn-outline-danger">退出登录</a>
            </div>
        </div>
    </nav>

    <div class="container mt-5">
        <div class="row justify-content-center">
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header" th:if="${product.id} == null">
                        <h3 class="text-center">添加产品</h3>
                    </div>
                    <div class="card-header" th:if="${product.id} != null">
                        <h3 class="text-center">编辑产品</h3>
                    </div>
                    <div class="card-body">
                        <form method="post" th:action="@{|/products/${product.id != null ? 'edit/' + product.id : 'add'}|}" th:object="${product}">
                            <div class="mb-3">
                                <label for="name" class="form-label">产品名称</label>
                                <input type="text" id="name" th:field="*{name}" class="form-control" required>
                            </div>
                            <div class="mb-3">
                                <label for="description" class="form-label">产品描述</label>
                                <textarea id="description" th:field="*{description}" class="form-control"></textarea>
                            </div>
                            <div class="mb-3">
                                <label for="price" class="form-label">产品价格</label>
                                <input type="number" step="0.01" id="price" th:field="*{price}" class="form-control" required>
                            </div>
                            <div class="d-grid gap-2">
                                <button type="submit" class="btn btn-primary">保存</button>
                                <a href="/products" class="btn btn-outline-secondary">返回列表</a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>    